//
//  NvRadiusUIView.m
//  NvSellerShow
//
//  Created by Meicam on 2017/1/6.
//  Copyright © 2017年 Meicam. All rights reserved.
//

#import "NvRadiusUIView.h"
@interface NvRadiusUIView()
    
    @property (nonatomic, assign)  CGFloat width;
    @property (nonatomic, assign)  CGFloat height;

@end

@implementation NvRadiusUIView

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        if(CGRectIsEmpty(frame)) {self.frame = CGRectMake(0, 0, 105, 105);};
        [self setupUI];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder
{
    if (self = [super initWithCoder:coder])
    {
        [self setupUI];
    }
    return self;
}

#pragma mark - 设置UI子控件
- (void)setupUI
{
    _imageView = [[UIImageView alloc]init];
    [self addSubview:_imageView];
    _textLabel = [[UILabel alloc]init];
    [self addSubview:_textLabel];
    _width =  self.frame.size.width;
    _height = self.frame.size.height;
    _textFont = 17;
    _foreGroundColor = [UIColor greenColor];
    _textColor = [UIColor whiteColor];
    
    _imageView.frame = CGRectMake(0, 0, 44, 44);
    _textLabel.frame = CGRectMake(44 ,44,self.frame.size.width-44,44);

}

- (void)setImage:(UIImage *)image
{
    [_imageView setImage:image];
}

- (void)makeImageRadius:(CGFloat)radius {
    if(!radius)
        radius = _radius;
    _imageView.layer.cornerRadius = radius;
    _imageView.layer.masksToBounds = YES;
}

- (void)setLabelText:(NSString *)labelText
{
    [_textLabel setText:labelText];
}

- (void)setLabelRect:(CGRect)labelRect
{
    [_textLabel setFrame:labelRect];
}

-(void)setImageRect:(CGRect)imageRect
{
    [_imageView setFrame:imageRect];
    
}

-(void)setViewRect:(CGRect)viewRect
{
    [self setFrame:viewRect];
}

-(void)setForeGroundColor:(UIColor *)foreGroundColor
{
    [self setBackgroundColor:foreGroundColor];
}

-(void)setTextFont:(CGFloat )textFont
{
    [_textLabel setFont:[UIFont systemFontOfSize:textFont]];
}

-(void)setTextColor:(UIColor *)textColor
{
    [_textLabel setTextColor:textColor];
}

-(void)setRadius:(CGFloat)radius
{
    _radius = radius;
    self.layer.cornerRadius = radius;
}

-(void)setViewAlpha:(CGFloat)alpha
{
    self.alpha = alpha;
}


-(void)setBorder:(CGFloat)border
{
    self.layer.borderWidth = border;
}

-(void)setBorderColor:(UIColor*)borderColor
{
   [self.layer setBorderColor:[borderColor CGColor]];
}

-(void)setLabelVisible:(BOOL)labelVisible
{
    _textLabel.hidden = !labelVisible;
}


@end
